package com.wuxi.common.domain;

import com.wuxi.common.exception.exceptionInfo.CommonException;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class R<T> {
    @Schema(description = "状态码", type = "int")
    private int code;
    @Schema(description = "状态消息", type = "String")
    private String msg;
    @Schema(description = "返回数据", type = "T")
    private T data;

    @Schema(description = "时间", type = "LocalDateTime")
    private LocalDateTime time;

    public static R<Void> ok() {
        return ok(null);
    }

    public static <T> R<T> ok(T data) {
        return new R<>(200, "OK", data);
    }

    public static <T> R<T> error(String msg) {
        return new R<>(500, msg + "请联系开发团队:test@foxmail.com", null);
    }

    public static <T> R<T> error(int code, String msg) {
        return new R<>(code, msg + "请联系开发团队:test@foxmail.com", null);
    }

    public static <T> R<T> error(CommonException e) {
        return new R<>(e.getCode(), e.getMessage() + "请联系开发团队:test@foxmail.com", null);
    }
    public static <T> R<T> error(CommonException e,T data) {
        return new R<>(e.getCode(), e.getMessage() + "请联系开发团队:test@foxmail.com", data);
    }

    public R() {
    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        // 获取当前的 LocalDateTime
        this.time = LocalDateTime.now();
    }

}